package databasetranslation;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.sql.SQLException;

import org.junit.Test;

import database.MySQLServer;
import database.SQLServer;

/**
 * Tests the payment list with a SQL server.
 */
public class testPaymentList extends TestPaymentList_noDB {
	
	@Override
	protected SQLServer buildServer() {
		return new MySQLServer("localhost","root","usbw");
	}
	
	@Test
	public void testGetEntry() throws SQLException {
		list.add(payment1);
		list.add(payment2);
		assertEquals(payment2, list.getEntry(payment2.getId()));
	}
	
	@Test
	public void testImportList() throws SQLException {
		list.add(payment1);
		list.add(payment2);

		SQLServer server = buildServer();
		ClientList clients = new ClientList(server);
		clients.importList();
		PaymentList list2 = new PaymentList(server, clients);
		list2.importList();
		assertEquals(list.getPayments(), list2.getPayments());
	}
	
	@Test
	public void testTruncate() throws SQLException {
		list.add(payment2);
		list.clearDatabaseTable();
		list.importList();
		assertTrue(list.getPayments().isEmpty());
	}

}
